package com.ruoyi.lession.controller;

import com.alipay.api.AlipayApiException;
import com.ruoyi.lession.entily.Order;
import com.ruoyi.lession.service.QuestService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("pay")
@CrossOrigin
public class AliPayController {

    //支付宝支付
    @Resource
    QuestService questService;

    /**
     * 支付宝支付
     * @param oid
     * @param servletResponse
     * @author 朱鑫杰
     */
    @GetMapping("/Alipay")
    public void ali(@RequestParam("oid") Integer oid , HttpServletResponse servletResponse){
    questService.Alipay(oid,servletResponse);
    }

    /**
     * 回调
     * @param request
     * @return
     * @throws AlipayApiException
     */
    @RequestMapping("/aliNotify")
    public String aliNotify(HttpServletRequest request) throws AlipayApiException {
      String aliNotify=questService.aliNotify(request);
      return aliNotify;
    }

    /**
     * 查询支付的结果并修改支付状态
     * @param outtradeno
     * @return
     * @throws AlipayApiException
     * @author 朱鑫杰
     */
    @PostMapping("/paylist")
    public String payList(@RequestParam("outtradeno") String outtradeno) throws AlipayApiException {
        String payList=questService.payList(outtradeno);
        return payList;
    }


}
